package springboot.test15.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import springboot.test15.interceptor.loginInterception;
import springboot.test15.interceptor.redisUrlCount;


@Configuration
public class AdminWebConfig implements WebMvcConfigurer {
    /*Filter Interceptor 拥有相同功能
      1.Filter是Servlet定义的原生组件 可以脱离Spring使用
      2.Interceptor是Spring定义的接口 可以使用Spring1的自动装配注解
    * */
    @Autowired
    redisUrlCount redisUrlCount;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new loginInterception())
                .addPathPatterns("/**")
                .excludePathPatterns("/","/login")
                .excludePathPatterns("/css/**","/fonts/**","/images/**","/js/**","/sql");
        //addPathPatterns("/**")会将所有请求拦截包括静态资源
        registry.addInterceptor(redisUrlCount)
                .addPathPatterns("/**")
                .excludePathPatterns("/css/**","/fonts/**","/images/**","/js/**","/sql");
    }
}
